﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CreativeMatrix.RemoteMedia.NetCore
{
	public class NetCoreModel
	{
		#region Singleton
		private NetCoreModel()
		{
		}

		static private NetCoreModel _instance = null;

		static public NetCoreModel GetIntance()
		{
			if (_instance == null)
				_instance = new NetCoreModel();

			return _instance;
		}
		#endregion

		/// <summary>
		/// User list container
		/// </summary>
		public List<Student> Users = new List<Student>();

		/// <summary>
		/// Represent teacher role
		/// </summary>
		public Teacher TheTeacher = null;

		public void TeacherLogin(string teacherName)
		{
			TheTeacher = new Teacher();
			TheTeacher.Name = teacherName;
			TheTeacher.Role = "teacher";
		}

		public void TeacherLogout()
		{
			ClearCommand("Teacher");
			TheTeacher = null;
		}

		/// <summary>
		/// Get user by username
		/// </summary>
		/// <param name="username">the user name</param>
		/// <returns>user object or null if no user found</returns>
		public Student GetUser(string username)
		{
			return NetCoreModel.GetIntance().Users.Find(x => x.Name == username);
		}

		/// <summary>
		/// Determind user if the user logined
		/// </summary>
		public bool IsUserLogin(string username)
		{
			if (string.IsNullOrEmpty(username) || null == GetUser(username))
				return false;

			return true;
		}

		/// <summary>
		/// Container to store the base64 image string
		/// </summary>
		//public List<string> ScreenshotList = new List<string>();

		public List<KeyValuePair<User, Command>> Commands = new List<KeyValuePair<User, Command>>();

		/// <summary>
		/// Remove the user command from the queue
		/// </summary>
		/// <param name="username"></param>
		public void ClearCommand(string username)
		{
			Commands.RemoveAll(x => x.Key.Name == username);
		}
	}
}